package q676_MagicDictionary;

public class MagicDictionary1 {

    /*
    最简单的方法 将dict记录下来 然后逐个比对是否差了一个字符
     */
    String[] dictionary;
    public MagicDictionary1() {

    }

    public void buildDict(String[] dictionary) {

        this.dictionary = dictionary;


    }

    public boolean search(String searchWord) {
        for (String s : dictionary) {
            if (s.length() == searchWord.length()) {
                int p = 0;
                for (int i = 0; i < s.length(); ++i) {
                    if (s.charAt(i) != searchWord.charAt(i)) ++p;
                    if (p > 1) break;
                }
                if (p == 1) return true;
            }
        }
        return false;
    }
}
